Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

feat: turn on event validation by default #562

Merged
merged 4 commits into from
Oct 24, 2024

Conversation

samika98
Copy link
Contributor

@samika98 samika98 commented Oct 15, 2024

Do not merge - for now
I am collecting evidence that this feature has been stable on durable for over a 1 week

@samika98 samika98 requested review from stbrody and a team as code owners October 15, 2024 19:24
@samika98 samika98 requested review from nathanielc and removed request for a team October 15, 2024 19:24
Copy link

linear bot commented Oct 15, 2024

Copy link
Collaborator

@nathanielc nathanielc left a comment

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

LGTM, but can you test if you can still disable it? I have had trouble passing false to boolean args in clap.

Also can you remove the language about the experimental flag being required?

@samika98
Copy link
Contributor Author

LGTM, but can you test if you can still disable it? I have had trouble passing false to boolean args in clap.

Also can you remove the language about the experimental flag being required?

@nathanielc tested it and turns out clap is weird with booleans. See this discussion : clap-rs/clap#1649 (comment). Turns out we need to explicitly pass the boolean and set the action so that we can set the variable.
So the current code leads us with :
'event-validation' = None -> gets set to true
'event-validation' in the args can hold either true/false.
'-- event-validation = false' -> gets set to false
'--event-validation = true' -> gets set to true

value_parser = clap::value_parser!(bool),
num_args = 0..=1,
action = ArgAction::Set,
env = "CERAMIC_ONE_EVENT_VALIDATION"
)]
event_validation: bool,
Copy link
Collaborator

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Re booleans being weird in clap. I think all we need to do re the issue you linked is set the to Option<bool> and then default it to true in our code like, opts.event_validation.unwrap_or(true).

Copy link
Contributor Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Yeah! we make it optional and don'e set a default value. Seems to work :

warning: unused import: `ArgAction`
  --> one/src/daemon.rs:17:12
   |
17 | use clap::{ArgAction, Args};
   |            ^^^^^^^^^
   |
   = note: `#[warn(unused_imports)]` on by default

warning: `ceramic-one` (lib) generated 1 warning (run `cargo fix --lib -p ceramic-one` to apply 1 suggestion)
    Finished `dev` profile [unoptimized + debuginfo] target(s) in 0.51s
     Running `target/debug/ceramic-one daemon`
  2024-10-22T18:08:19.257286Z  INFO ceramic_one::daemon: Event service created, event_validation: true
^C
samikas@Samikas-MacBook-Pro rust-ceramic % RUST_LOG=info,ceramic_olap=debug cargo run --bin ceramic-one -- daemon --event-validation=false | grep "Event service created"
warning: unused import: `ArgAction`
  --> one/src/daemon.rs:17:12
   |
17 | use clap::{ArgAction, Args};
   |            ^^^^^^^^^
   |
   = note: `#[warn(unused_imports)]` on by default

warning: `ceramic-one` (lib) generated 1 warning (run `cargo fix --lib -p ceramic-one` to apply 1 suggestion)
    Finished `dev` profile [unoptimized + debuginfo] target(s) in 0.50s
     Running `target/debug/ceramic-one daemon --event-validation=false`
  2024-10-22T18:08:39.913484Z  INFO ceramic_one::daemon: Event service created, event_validation: false```

Copy link
Contributor Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Added setting the default value using default_value. Added reasoning in the commit message incase anyone is interested in the workings of default_value vs default_value_t, why one works and the other does not

Samika Kashyap added 2 commits October 22, 2024 11:09
…_t=Some(true) will break the code. The default_value_t cannot be used here : The default_value_t attribute in Clap requires the type to implement Display because it needs to be able to print the default value in the help text. However, Option<T> does not implement Display, even if T does. To work around this, we use default_value instead This works because Clap will parse the string true into a bool and then wrap it in Some(...). We have additionally also handled this in the code parsing using an unwrap_or(). The default_value is added more for semantic purposes to aid readability of the code
@nathanielc nathanielc added this pull request to the merge queue Oct 24, 2024
Merged via the queue into main with commit 0b0e5ae Oct 24, 2024
5 checks passed
@nathanielc nathanielc deleted the feature/aes-382-enable-event-validation-by-default branch October 24, 2024 18:41
@smrz2001 smrz2001 mentioned this pull request Nov 4, 2024
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
None yet
Projects
None yet
Development

Successfully merging this pull request may close these issues.

3 participants